<?php


namespace app\logic\model;


use think\Model;

class UserFocus extends Model
{
    protected $name="user_focus";
    /**
     * 获取关注数
     * @param $list
     */
    function getFollowNum($param){
        if(!empty($param)){
            $param['follow']=$this->where("user_id",$param['id'])->where('status',1)->count();//关注数
            $param['be_follow']=$this->where("focus_id",$param['id'])->where('status',1)->count();//被关注数
        }
        return $param;
    }

    /**
     * 当前用户是否关注指定用户
     * @param $focus_id int 被关注的人
     */
    function checkFollowed($focus_id){
        global $user;
        if(!empty($user)){
            return $this->where("user_id",$user['id'])
                ->where("focus_id",$focus_id)
                ->value("status")?true:false;
        }
        return false;
    }
}